package _2响应头;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/test2")
public class Test2Servlet extends HttpServlet{
	
	
	int count = 0;
	

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		
		// 设置自定义信息
		resp.setHeader("username", "zhangsan");
		resp.setHeader("age", "18");
		
		// 跳转
		
		// 方式1:
//		resp.setStatus(302); // 跳转
//		resp.setHeader("location", "https://wwww.baidu.com");
		
		// 方式2:
//		resp.setHeader("refresh", "3,url=https://www.baidu.com");
		// 当前定时刷新
//		resp.setHeader("refresh", "1,url=http://localhost:8080/05-Response/test2");
		
		// 方式3:
//		resp.sendRedirect("https://www.baidu.com");
		
		
		// 编码信息
		resp.setHeader("Content-Type","text/html;charset=utf-8");
		// 
//		resp.setContentType("text/html;charset=utf-8");
		
		count++;
		resp.getWriter().print("中文test:"+count);
		
	}
}
